package com.chenwy.example.service;
import com.chenwy.example.dao.main.SlaveMapper;
import com.chenwy.example.entity.main.Slave;
import com.chenwy.example.repository.main.SlaveRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
 * Created by Administrator on 2019/5/6.
 */
@Service
public class SlaveService {

    @Autowired
    private SlaveMapper slaveMapper;

    @Autowired
    private SlaveRepository slaveRepository;

    public Slave get(Long id){
        return slaveMapper.selectByPrimaryKey(id);
    }

    @Autowired
    SlaveService slaveService;

    @Transactional(propagation = Propagation.REQUIRES_NEW,isolation = Isolation.READ_COMMITTED)
    public void save(Slave slave){
//        Slave slave1 = new Slave();

//        slave1.setSla("111");
//        slave1.setMasId(null);
//        slaveRepository.save(slave1);
        this.save2(slave);
    }

    public void save1(){
//        save2();
    }

    @Transactional(isolation = Isolation.SERIALIZABLE)
    public void save2(Slave slave){
        slaveRepository.save(slave);
        Slave slave1 = new Slave();
        slave1.setSla("111");
        slave1.setMasId(null);
        slaveRepository.save(slave1);
    }
}
